#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<unistd.h>
#include<pthread.h>

/*
   循环创建子进程
 */

void* mythread(void *arg)
{
	int*p = (int*)arg;
	printf("[%d]:child thread,pid=[%d],id=[%ld]\n",*p,getpid(),pthread_self());
}


int main()
{
	int i = 0;
	int arr[5];
	int ret;
	int num = 99;
	pthread_t thread; //返回线程号	
	for(i;i<5;i++)
	{
		arr[i] = i;
		ret = pthread_create(&thread,NULL,mythread,&arr[i]);
		if(ret != 0)
		{
			printf("thread creat error,[%s]\n",strerror(ret));
			return -1;
		} 
	}
	printf("parent thread,pid=[%d],id=[%ld]\n",getpid(),pthread_self());

	//目的是为了让子线程能够执行起来
	sleep(1);


	return 0;
}
